package com.woniu.controller;

import com.woniu.dao.AnnouncementMapper;
import com.woniu.dto.NoticePost;
import com.woniu.pojo.Announcement;
import com.woniu.result.CommonResult;
import com.woniu.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    /**
     * 查询社区公告
     * @param key 社区名关键字
     * @param page 当前页，即第几次加载，每次加载10条数据
     * @return
     */
    @GetMapping("/list")
    @ResponseBody
    public CommonResult list(String key,Integer page){
        System.out.println(key+":"+page);
        List<NoticePost> noticePosts = noticeService.selectByKey(key,page);
        System.out.println(noticePosts.size());
        return CommonResult.success(noticePosts);
    }
@Autowired
private AnnouncementMapper announcementMapper;
    @GetMapping("/test")
    @ResponseBody
    public String test(String testText){
        System.out.println(testText);
        Announcement announcement = new Announcement();
        announcement.setId(16);
        announcement.setContext(testText);
        announcementMapper.insertSelective(announcement);
        return announcementMapper.selectByPrimaryKey(announcement.getId()).getContext();
    }
}
